<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./js/vue.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
            list-style: none;
        }

        .success {
            color: green
        }

        .error {
            color: red
        }
    </style>
</head>

<body>
    <div id="app">
        <div v-for="item in list">
            {{item.name}} <input :value="item.value" @input="checkAttr(item)" />
            <span :class="item.class">{{item.tip}}</span>
        </div>

    </div>

</body>
<script>
    new Vue({
        el: "#app",
        data: {
            list: [{
                name: "username",
                value: "",
                reg: /^[a-z_$][0-9a-z_$]{5,9}$/i,
                msg: "请输出数字字母_$组成并且不能以数字开头长度6到10位",
                tip: "请输出数字字母_$组成并且不能以数字开头长度6到10位",
                class: "error"
            }, {
                name: "userpwd",
                value: "",
                reg: /^[a-z0-9]{6,10}$/i,
                tip: "密码数字字母组成长度6到10位",
                msg: "密码数字字母组成长度6到10位",
                class: "error"

            }, {
                name: "usertel",
                value: "",
                reg: /^1[3-9][0-9]{9}$/,
                tip: "请输入常用的手机号",
                msg: "请输入常用的手机号",
                class: "error"
            }]


        },
        methods: {
            checkAttr(item) {
                item.value = window.event.target.value;
                if (item.reg.test(item.value)) {
                    item.tip = "√";
                    item.class = "success";
                } else {
                    item.tip = item.msg;
                    item.class = "error";
                }
            }

        },

    })


</script>

</html>